<script>
function viewObject(name)
{
 var obj = eval(name), i;
 
 if(!obj) 
 { 
   alert(name + " is not an object"); 
   return;
 }
 
 var w_Test = open("","Test","width=600,height=500,scrollbars=1");
 
 if(!w_Test)
 { 
   alert("Cannot open window for "+name); 
   return; 
 }
 
 w_Test.document.open();
 
 for(i in obj)
   w_Test.document.write(name+"."+i+"="+obj[i]+"<br>");
 
 w_Test.document.close();
}	
	
</script>	

<SCRIPT defer>
var TxtRange;
TxtRange = dialogArguments.document.selection.createRange();

function _CloseOnEsc() {
  if (event.keyCode == 27) { window.close(); return; }
}
window.onerror = HandleError

function HandleError(message, url, line) {
  var str = "An error has occurred in this dialog." + "\n\n"
  + "Error: " + line + "\n" + message;
	  alert(str);
	  window.close();
	  return true;
}

// event handlers
function Init() {
	document.body.onkeypress = _CloseOnEsc;
}

//Match Case and Whole Words
function matchtype(){
    var retval = 0;
    var matchcase = 0;
    var matchword = 0;
    if (document.formSearch.MatchCase.checked) matchcase = 4;
    if (document.formSearch.MatchWholeWord.checked) matchword = 2;
    retval = matchcase + matchword;
    return(retval);
}

//Checks for Find field not empty
function checkInputString(){
    if (document.formSearch.stringSearch.value.length < 1) {
        alert("Nothing to search.\nPlease enter some text in the field labeled Find what:");
        return false;
    } else {
        return true;
    }
}

// Finds the entered text
function FindTxt(){
    if (checkInputString()) {
        var searchval = document.formSearch.stringSearch.value;
        TxtRange.collapse(false);
        if (TxtRange.findText(searchval, 1000000000, matchtype())) {TxtRange.select();}
			else {
            var startAgain = confirm("Finished Searching the document. Would you like to start again from the top of the page?");
            if (startAgain) {
                TxtRange.expand("textedit");
                TxtRange.collapse();
                TxtRange.select();
                FindTxt();
            }
        }
    }
}

// replaces the first found instance of the entered textwith the desired text
function ReplaceTxt(){
    if (checkInputString()) {
        if (document.formSearch.MatchCase.checked){
            if (TxtRange.text == document.formSearch.stringSearch.value) TxtRange.text = document.formSearch.stringReplace.value
        }
		else {
            if (TxtRange.text.toLowerCase() == document.formSearch.stringSearch.value.toLowerCase())
			TxtRange.text = document.formSearch.stringReplace.value
			}
        	FindTxt();
    	}
	}

// replaces all instances of the entered text with the desired text
function ReplaceAllTxt(){
    if (checkInputString()) {
        var searchval = document.formSearch.stringSearch.value;
        var wordcount = 0;
        var msg = "";
        TxtRange.expand("textedit");
        TxtRange.collapse();
        TxtRange.select();
        while (TxtRange.findText(searchval, 1000000000, matchtype())){
            TxtRange.select();
            TxtRange.text = document.formSearch.stringReplace.value;
            wordcount++;
        }
        if (wordcount == 0) msg = "Word not found. Nothing replaced."
        else msg = wordcount + " word(s) were replaced.";
        alert(msg);
    }
}
</SCRIPT>

<body id="bdy" style="BACKGROUND: buttonface; COLOR: windowtext" scroll="no" onload="Init()">
<form name="formSearch" action="" method="post">
<table cellspacing="0" cellpadding="5" border="0">
<tbody>
<tr>
<td valign="top" nowrap="nowrap" align="left"><label for="null">Find what:</label><br /><input id="stringSearch" style="WIDTH: 280px; HEIGHT: 22px" size="40" value="" name="stringSearch" /><br /><label for="null">Replace with:</label><br /><input id="stringReplace" style="WIDTH: 280px; HEIGHT: 22px" size="40" value="" name="stringReplace" /><br /><input id="MatchWholeWord" type="checkbox" size="40" value="on" name="MatchWholeWord" /><label for="null">Match whole word only</label><br /><input id="MatchCase" type="checkbox" size="40" value="on" name="MatchCase" /><label for="null">Match case</label> </td>
<td valign="top" rowspan="2"><button style="MARGIN-TOP: 15px; WIDTH: 75px; HEIGHT: 22px" onclick="FindTxt();" name="Find">Find Next</button><br /><button style="MARGIN-TOP: 7px; WIDTH: 75px; HEIGHT: 22px" onclick="ReplaceTxt();" name="Replace">Replace</button><br /><button style="MARGIN-TOP: 7px; WIDTH: 75px; HEIGHT: 22px" onclick="ReplaceAllTxt();" name="Replaceall">Replace All</button><br /><button style="MARGIN-TOP: 7px; WIDTH: 75px; HEIGHT: 22px" onclick="window.close();" name="Cancel">Close</button><br /></td></tr></tbody></table></form>
</body>
</html>
